'use strict'

import React, {Component} from 'react'
import {
    StyleSheet,
    ActivityIndicator
} from 'react-native'
import GlobalStyles from '../../constants/GlobalStyles'

import AlertContent from './AlertContent';
import { bouncer } from '../../utils/Tool';
import { Overlay } from 'teaset';

class AlertManager {

    static popViewRefs = []

    // params = {
    //     title: '温馨提示asdasd',
    //     titleStyle: {},
    //     detail: '详细描述',
    //     detailStyle: {},
    //     actions: [
    //         { title: '取消', titleStyle: {}, onPress: () => alert('取消') },
    //         { title: '确定', titleStyle: {}, onPress: () => alert('取消') },
    //     ]
    // }

    static show(params,option={}) {
        this.showPopView(<AlertContent {...params} />, option)
    }

    static showPopView(component, option = {}) {
        this.popViewRefs = bouncer(this.popViewRefs.slice()) // 过滤
        console.log('this.popViewRefs1---->', this.popViewRefs);
        Overlay.show(
            <Overlay.PopView
                ref={v => this.popViewRefs.push(v)}
                style={{ justifyContent: 'center', alignItems: 'center', }}
                type={'zoomOut'}
                modal={option.modal || false}
                onCloseRequest={() => {
                    !option.modal && this.hide();
                }}
                {...option}
            >
                {component}
            </Overlay.PopView>
        )
    }

    static hide() {
        this.popViewRefs = bouncer(this.popViewRefs.slice()) // 过滤
        console.log('this.popViewRefs2---->', this.popViewRefs);
        if (this.popViewRefs.length > 0) {
            const lastRef = this.popViewRefs.pop()
            lastRef.close();
        }
        console.log('this.popViewRefs3---->', this.popViewRefs);
    }

}

//make this component available to the app
export default AlertManager;